package gaobo.arraylist.poker;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Pokers {

    public static final String[] SUITS ={"♥","♠","♣","♦"};

    public static List<Poker> buyPokers(){
        //构造扑克牌
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                //消除提示
 //               int rank = j;
                Poker poker = new Poker(suit,j);
                pokerList.add(poker);
            }
        }
        return pokerList;
    }
    //洗牌
    public static void swap(List<Poker> pokerList,int i,int j){
        Poker tmp = pokerList.get(i);
        pokerList.set(i,pokerList.get(j));
        pokerList.set(j,tmp);
    }

    public static void shuffle(List<Poker> pokerList){
        Random random = new Random();
        for (int i = pokerList.size()-1; i > 0 ; i--) {
            int index = random.nextInt(i);
            swap(pokerList,i,index);
        }
    }


    //揭牌
    public static void main(String[] args) {
        List<Poker> pokerList = buyPokers();
//        for (Poker p: pokerList) {
//            System.out.println(p);
//        }
        System.out.println("新牌:" + pokerList);
        shuffle(pokerList);
        System.out.println("洗牌:" + pokerList);
        //揭牌:3个人每人轮流抓3张
        //1.如何描述3个人？
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        //2.如何区分往哪个人手里放牌？
        //通过集合实现二维数组
        List<List<Poker>> hand = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                List<Poker> handTmp = hand.get(j);//来确定是谁的手
                handTmp.add(pokerList.remove(0));//每次都是0下标

            }
        }
        for (int i = 0; i < hand.size(); i++) {
            System.out.println("第" + (i+1) + "个人的牌是:" + hand.get(i));
        }

        System.out.println("剩余的牌:" + pokerList);
    }





}
